﻿/**
 * ...
 * @author Sergey Mamyan
 */

package tx.squirrel.neko.admin.handler;

import mtwin.web.Request;
import neko.Web;
import tx.squirrel.neko.core.handler.BaseHandler;
import tx.squirrel.neko.core.model.Config;
import tx.squirrel.neko.core.model.Session;

class AdminHandler extends BaseHandler {
	
	public function new() {
		super();
		logged("default", null,					doDefault	);
		logged("config",  "admin_config.mtt", 	doConfig	);
		logged("session", "admin_session.mtt",	doSession	);
		logged("user", handler(new UserHandler()));
		logged("application", handler(new ApplicationHandler()));
	}
	
	public function doDefault():Void {
		redirect("/admin/config");
	}
	
	public function doConfig():Void {
		if (Web.getMethod() == "POST") {
			Config.data = Web.getParams();
			Config.save();
			Session.writeLog("info", "Configuration saved");
			redirect("/admin/config");
		}else{
			display(Config.manager.all());
		}
	}
	
	public function doSession():Void {
		display();
	}
}